<?php
include_once('DataBase.php');
/*
 * Class designed to model the database table 'loan'
 */
class Loan{
    //Attributes
    
    //Quote of the book loaned
    private $quote;
    //Carnet of the student that owns the book
    private $carnet;
    //String representation of the date the book was rented
    private $rentDate;
    //String representation of the date the book must be returned
    private $timeline;
    //Current fee to be payed for the book
    private $fee;
    //Days the student has passed the timeline
    private $daysFee;
    
    //Methods
    
    //Builds a loan object with the information specified
    //The rent date and tiemline must be specified in the format YYYY-MM-DD
    public function __construct($quote, $carnet, $rentDate, $timeLine, $daysFee){
        $this->quote = $quote;
        $this->carnet = $carnet;
        $date = explode("-", $rentDate);
        $this->rentDate = $date[2].'/'.$date[1].'/'.$date[0];
        $date = explode("-", $timeLine);
        $this->timeLine = $date[2].'/'.$date[1].'/'.$date[0];
        $this->daysFee = $daysFee;
        if($daysFee > 0){
            $this->fee = $daysFee * 1;
        }else{
            $this->fee = 0;
        }
    }
    /*
     * Gets all loans present in the database
     *
     * Return value: Array of Loan objects representing all the loans in the system
     */
    public static function getAllLoans(){
        $database = DataBase::getInstance();
        return $database->getAllLoans();
    }
    
    //List of getters
    public function getQuote(){return $this->quote;}
    public function getCarnet(){return $this->carnet;}
    public function getRentDate(){return $this->rentDate;}
    public function getTimeline(){return $this->timeline;}
    public function getFee(){return $this->fee;}
    public function getDaysFee(){return $this->daysFee;}
    
    //List of setters
    public function setQuote($a){$this->quote = $a;}
    public function setCarnet($a){$this->carnet = $a;}
    public function setRentDate($a){$this->rentDate = $a;}
    public function setTimeline($a){$this->timeline = $a;}
    public function setFee($a){$this->fee = $a;}
    public function setDaysFee($a){$this->daysFee = $a;}
}
?>